package com.yanqu.road.server.cmd.player;

import com.yanqu.road.entity.player.DestroyRoleInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.common.ConfigProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.minibind.WechatBindModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_WECHAT_BIND_ROLE_GET_BIND_STRING, desc = "小程序绑定角色获得绑定码")
public class GetWechatBindRoleGetBindStringCmd extends AbstractCommand {
    private DestroyRoleInfo destroyRoleInfo = null;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        //绑角码： 加密前参数格式： 平台 uid|服 id|角色 id|角色名|游戏 id|当前时间戳
        ret = player.getModule(WechatBindModule.class).checkReqValid();
        if (ret != 0){
            return;
        }
        if(player.getModule(WechatBindModule.class).getUserData().isBind()){
            ret = GameErrorCode.E_WX_BIND_WAS_BIND;
            return;
        }
        String bindCode = player.getModule(WechatBindModule.class).getBindCode();
        ConfigProto.WechatBindRoleGetBindStringRespMsg.Builder respMsg = ConfigProto.WechatBindRoleGetBindStringRespMsg.newBuilder();
        respMsg.setRet(0);
        respMsg.setBindString(bindCode);
        player.sendPacket(ClientProtocol.U_WECHAT_BIND_ROLE_GET_BIND_STRING, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret > 0){
            player.sendPacket(ClientProtocol.U_WECHAT_BIND_ROLE_GET_BIND_STRING, ConfigProto.WechatBindRoleGetBindStringRespMsg.newBuilder().setRet(ret));
        }
    }
}
